﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVC4Shop.dao;
using MVC4Shop.Models;

namespace MVC4Shop.Controllers
{
    public class SizeController : Controller
    {
        //
        // GET: /Size/

        public ActionResult Index()
        {

            return View(SizeDAO.GetAll());
        }

        //
        // GET: /Size/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Size/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Size/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here
                SizeModel model = new SizeModel();
                model.name = collection["name"].ToString();
                SizeDAO.Insert(model);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Size/Edit/5

        public ActionResult Edit(int id)
        {

            return View();
        }

        //
        // POST: /Size/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
                SizeModel model = new SizeModel();
                model.name =  collection["name"].ToString();
                model.id = id.ToString();
                SizeDAO.Edit(model);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Size/Delete/5

        public ActionResult Delete(int id)
        {

            return View();
        }

        //
        // POST: /Size/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
                SizeDAO.Delete(id.ToString());
                    return RedirectToAction("Index");
 
            }
            catch
            {
                return View();
            }
        }
    }
}
